/* 
 * oms，一个基于J2EE架构运营支撑平台
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.dao.system.impl;

import java.util.List;

import org.grayrabbit.cms.dao.system.PluginVersionDao;
import org.grayrabbit.cms.entity.PluginVersion;
import org.grayrabbit.cms.vo.system.PluginVersionBean;
import org.springframework.stereotype.Repository;

import org.grayrabbit.dao.impl.GenericHibernateDao;
import org.grayrabbit.dao.util.Page;
import org.grayrabbit.dao.util.QueryCondition;

/**
 * <b>PluginVersion</b> dao implementation 

 * @version 1.0，创建时间：2012-01-05 17:01:09 
 */
@Repository
public class PluginVersionDaoImpl extends GenericHibernateDao<PluginVersion, String>
		implements PluginVersionDao {

	/**
	 * HQL主体语句
	 */
	public static final String MAIN_HQL = "From PluginVersion as obj";
	/**
	 * HQL中count统计hql片段
	 */
	public static final String COUNT_HQL = "Select Count(obj) ";

	/**
	 * 根据bean组装查询条件
	 * @see PluginVersionDao#assembly(PluginVersionBean)
	 */
	public QueryCondition assembly(PluginVersionBean bean) {
		QueryCondition qc = new QueryCondition(MAIN_HQL);
		trans(bean,qc);
		return qc;
	}

	/**
	 * 根据bean组装统计查询条件
	 * @see PluginVersionDao#assemblyCount(PluginVersionBean)
	 */
	public QueryCondition assemblyCount(PluginVersionBean bean) {
		QueryCondition qc = new QueryCondition(COUNT_HQL + MAIN_HQL);
		trans(bean,qc);
		return qc;
	}

	/**
	 * @see PluginVersionDao#count(PluginVersionBean)
	 */
	public int count(PluginVersionBean bean) {
		return ((Long)iterator(assemblyCount(bean)).next()).intValue();
	}

	/**
	 * 根据bean组装查询条件(名称参数)
	 * @see PluginVersionDao#assemblyQuery(PluginVersionBean)
	 */
	public QueryCondition assermblyQuery(PluginVersionBean bean) {
		QueryCondition qc = new QueryCondition(MAIN_HQL);
		trans(bean, qc);
		return qc;
	}

	/**
	 * 根据bean组装统计查询条件(名称参数)
	 * @see PluginVersionDao#assemblyQueryCount(PluginVersionBean)
	 */
	public QueryCondition assemblyQueryCount(PluginVersionBean bean) {
		QueryCondition qc = new QueryCondition(COUNT_HQL + MAIN_HQL);
		trans(bean,qc);
		return qc;
	}

	/**
	 * 填充分页组件
	 * @see PluginVersionDao#findByPage(Page, PluginVersionBean)
	 */
	public List<PluginVersion> findByPage(Page<PluginVersion> page,
			PluginVersionBean bean) {
		QueryCondition qc = assembly(bean);
		qc.setMaxResults(page.getPageSize());
		qc.setOffset(page.getOffset());
		return findByQc(qc);
	}
	// 业务查询主要逻辑代码
	private void trans(PluginVersionBean bean,QueryCondition qc){
		//TODO:兄弟们此处根据业务修改代码，完成后，请删除本行，沈永生于2012-01-05 17:01:09提醒!
		if(bean!=null){
		            if(bean.getName() != null){
				qc.add(" And obj.name like ? ", "%"+bean.getName()+"%");
			}
            if(bean.getKey() != null){
				qc.add(" And obj.key like ? ", "%"+bean.getKey()+"%");
			}
            if(bean.getCreated() != null){
				qc.add(" And obj.created like ? ", "%"+bean.getCreated()+"%");
			}
            if(bean.getIsEnabled() != null){
				qc.add(" And obj.isEnabled like ? ", "%"+bean.getIsEnabled()+"%");
			}
            if(bean.getTopNavUrl() != null){
				qc.add(" And obj.topNavUrl like ? ", "%"+bean.getTopNavUrl()+"%");
			}
            if(bean.getCatalogNavUrl() != null){
				qc.add(" And obj.catalogNavUrl like ? ", "%"+bean.getCatalogNavUrl()+"%");
			}
            if(bean.getHeadHNavUrl() != null){
				qc.add(" And obj.headHNavUrl like ? ", "%"+bean.getHeadHNavUrl()+"%");
			}
            if(bean.getLeftVNavUrl() != null){
				qc.add(" And obj.leftVNavUrl like ? ", "%"+bean.getLeftVNavUrl()+"%");
			}
            if(bean.getManageConfigUrl() != null){
				qc.add(" And obj.manageConfigUrl like ? ", "%"+bean.getManageConfigUrl()+"%");
			}
            if(bean.getIsAutoDeploy() != null){
				qc.add(" And obj.isAutoDeploy like ? ", "%"+bean.getIsAutoDeploy()+"%");
			}

		}
	}


}